package response

import (
	"net/http"
	"vblog/exception"

	"github.com/gin-gonic/gin"
)

func Success(c *gin.Context, data any) {
	c.JSON(http.StatusOK, data)
}

func Fail(c *gin.Context, err error) {
	defer c.Abort()
	
	var e *exception.Error
	if v, ok := err.(*exception.Error); ok {
		e = v
	} else {
		e = exception.New(http.StatusInternalServerError, err.Error())
	}
	c.JSON(http.StatusInternalServerError, e)
}
